package com.njtoyo.taxi.admin.rest.controller.business;

import cn.hutool.core.lang.Dict;
import com.njtoyo.taxi.admin.aop.LoggerManage;
import com.njtoyo.taxi.admin.aop.PermissionScope;
import com.njtoyo.taxi.admin.rest.presenter.business.simple_call.backlog.InitRecordListPresenter;
import com.njtoyo.taxi.admin.rest.wrapper.business.simple_call.backlog.*;
import com.njtoyo.taxi.admin.service.business.SimpleCallBacklogService;
import com.taxi.entity.common.RestResult;
import com.njtoyo.taxi.entity.backend.AdminUser;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.annotations.ApiIgnore;

import javax.validation.Valid;
import java.util.List;

@RestController
@Api(value = "电召记录", tags = "电召记录")
@RequestMapping("business/simple_call/backlog")
public class SimpleCallBacklogController {

    @Autowired
    private SimpleCallBacklogService simpleCallBacklogService;

    @GetMapping("/init")
    @ApiOperation(value = "待处理电召记录", notes = "获取未处理的电召数据，可传最大id进行筛选, 权限：simple_call_backlog_init")
    @PermissionScope(names = {"simple_call_backlog_init"})
    RestResult<List<InitRecordListPresenter>> getInitRecord(@ApiIgnore @ModelAttribute("admin") AdminUser adminUser, GetInitRecordWrapper wrapper) {
        return simpleCallBacklogService.getInitRecord(adminUser, wrapper);
    }

    @PatchMapping("/{id}")
    @ApiOperation(value = "更新位置信息", notes = "更新上车点的位置信息，权限：simple_call_backlog_update_origin")
    @PermissionScope(names = {"simple_call_backlog_update_origin"})
    @LoggerManage(description = "更新电召单位置信息")
    RestResult update(@ApiIgnore @ModelAttribute("admin") AdminUser adminUser, @PathVariable("id") Long id, @Valid @RequestBody UpdateOriginWrapper wrapper) {
        return simpleCallBacklogService.update(adminUser, id, wrapper);
    }

    @PostMapping("/{id}/send")
    @ApiOperation(value = "发单接口", notes = "电召数据的发单接口，权限：simple_call_backlog_send")
    @PermissionScope(names = {"simple_call_backlog_send"})
    @LoggerManage(description = "发送电召单")
    RestResult send(@ApiIgnore @ModelAttribute("admin") AdminUser adminUser, @PathVariable("id") Long id, @Valid @RequestBody SendWrapper wrapper) {
        return simpleCallBacklogService.send(adminUser, id, wrapper);
    }

    @PostMapping("/{id}/cancel")
    @ApiOperation(value = "取消订单", notes = "取消订单，权限：simple_call_backlog_cancel")
    @PermissionScope(names = {"simple_call_backlog_cancel"})
    @LoggerManage(description = "取消电召单")
    RestResult cancel(@ApiIgnore @ModelAttribute("admin") AdminUser adminUser, @PathVariable("id") Long id, @Valid @RequestBody CancelWrapper wrapper) {
        return simpleCallBacklogService.cancel(adminUser, id, wrapper);
    }

    @PostMapping("/send-phone")
    @PermissionScope(names = {"simple_call_backlog_send"})
    RestResult<?> sendPhone(@ModelAttribute("admin") AdminUser adminUser, @RequestBody SendPhoneWrapper wrapper) {
        return simpleCallBacklogService.sendPhone(adminUser, wrapper);
    }


    @PostMapping("/{callId}/sendMsg")
    RestResult sendMsg(@PathVariable Long callId, @RequestBody Dict params) {
        return simpleCallBacklogService.sendMsg(callId, params);
    }
}
